package com.ktjy.service.Impl;

import com.ktjy.entity.AuctionUser;
import com.ktjy.mapper.AuctionUserMapper;
import com.ktjy.service.AuctionUserService;
import com.ktjy.util.MyBatisUtil;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.SqlSession;

public class AuctionUserServiceImpl implements AuctionUserService {
    @Override
    public boolean registerAuctionuser(AuctionUser auctionuser) {
        try (SqlSession sqlSession = MyBatisUtil.createSqlSession()) {
            try {
                AuctionUserMapper mapper = sqlSession.getMapper(AuctionUserMapper.class);
                boolean result = mapper.insert(auctionuser) > 0;
                sqlSession.commit(); // 提交事务
                return result;
            } catch (Exception e) {
                sqlSession.rollback(); // 回滚事务
                throw e;
            }
        }
    }

    @Override
    public AuctionUser login(String username, String password) {
         try (SqlSession sqlSession = MyBatisUtil.createSqlSession()) {
            AuctionUserMapper mapper = sqlSession.getMapper(AuctionUserMapper.class);
            return mapper.login(username, password);
        }
    }
}
